
<template>
  <div class="bank-login-wrapper">
    <!-- 开场动画容器 -->
    <div v-if="showAnimation" class="animation-container">
      <!-- 银行卡元素 -->
      <div class="bank-card">
        <div class="card-chip"></div>
        <div class="card-number">Best Wishes To You !</div>
        <div class="card-info">
          <span>制作人: 武岳 于红光</span>
          <span>BANK</span>
        </div>
      </div>

      <div class="bank-logo">
        <el-icon :class="{ 'scale-up': animationCompleted }"><Coin /></el-icon>
      </div>
      <div
          v-for="(coin, index) in coinCount"
          :key="index"
          class="falling-coin"
          :style="{
          left: `${Math.random() * 100}%`,
          animationDelay: `${index * 0.1}s`,
          '--coin-size': `${30 + Math.random() * 20}px`,
        }"
      >
        <el-icon><Coin /></el-icon>
      </div>
    </div>

    <!-- 登录选择界面（动画结束后显示） -->
    <el-transition name="fade" mode="out-in">
      <div v-if="!showAnimation" class="select-login-container">
        <h2>选择登录类型</h2>
        <div class="login-options-slider">
          <div class="slider-track">
            <div :class="['slider-item', { active: activeLoginType === 'customer' }]" @click="activeLoginType = 'customer'">
              <div class="icon-container">
                <el-icon><User /></el-icon>
              </div>
              <span>用户登录</span>
            </div>
            <div :class="['slider-item', { active: activeLoginType === 'manager' }]" @click="activeLoginType = 'manager'">
              <div class="icon-container">
                <el-icon><Setting /></el-icon>
              </div>
              <span>管理员登录</span>
            </div>
          </div>
        </div>
        <div class="login-button-container">
          <el-button type="primary" @click="handleLogin" class="login-button">
            登录
          </el-button>
        </div>
      </div>
    </el-transition>
  </div>
</template>

<script>
import { ref, onMounted } from "vue";
import { useRouter } from "vue-router";
import { User, Setting, Coin } from "@element-plus/icons-vue";

export default {
  components: {
    User,
    Setting,
    Coin
  },
  setup() {
    const router = useRouter();
    const showAnimation = ref(true);
    const animationCompleted = ref(false);
    const coinCount = 30; // 金币数量
    const activeLoginType = ref('customer'); // 默认选中用户登录

    // 动画结束后显示登录界面
    const handleAnimationEnd = () => {
      showAnimation.value = false;
      animationCompleted.value = true;
    };

    // 初始化动画
    onMounted(() => {
      setTimeout(() => {
        handleAnimationEnd();
      }, 5000);
    });

    // 跳转到用户登录页
    const goToCustomerLogin = () => {
      router.push("/customer-login");
    };

    // 跳转到管理员登录页
    const goToManagerLogin = () => {
      router.push("/login");
    };

    // 处理登录按钮点击
    const handleLogin = () => {
      if (activeLoginType.value === 'customer') {
        goToCustomerLogin();
      } else {
        goToManagerLogin();
      }
    };

    return {
      showAnimation,
      animationCompleted,
      coinCount,
      activeLoginType,
      goToCustomerLogin,
      goToManagerLogin,
      handleLogin,
    };
  },
};
</script>

<style scoped lang="scss">
// 使用SCSS预处理器
$primary-gradient: linear-gradient(to right, #1a73e8, #4285f4);
$card-gradient: linear-gradient(to right, #3498db, #2980b9);
$coin-color: #ffd700;
$slider-bg: linear-gradient(to right, #f5f7fa, #e4e7ed);

// 基础容器样式
.bank-login-wrapper {
  position: relative;
  width: 100%;
  height: 100vh;
  overflow: hidden;
  background: $primary-gradient;
}

// 动画容器样式
.animation-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: $primary-gradient;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10;
}

// 银行标志样式
.bank-logo {
  position: absolute;
  top: 30%; /* 调整标志位置 */
  width: 120px;
  height: 120px;
  background-color: white;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
  z-index: 2;
  animation: logoAppear 2s ease-out forwards;
}

// 银行卡元素样式
.bank-card {
  position: absolute;
  bottom: 10%; /* 从屏幕底部10%位置开始 */
  left: 50%;
  transform: translateX(-50%);
  width: 80%;
  max-width: 450px;
  height: auto;
  background: $card-gradient;
  border-radius: 10px;
  box-shadow: 0 15px 30px rgba(0, 0, 0, 0.3);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 25px;
  color: white;
  animation: cardFloat 3s ease-out forwards;
  z-index: 3;
}

.card-chip {
  width: 40px;
  height: 30px;
  background-color: #9b9b9b;
  border-radius: 3px;
  margin-bottom: 20px;
  position: absolute;
  left: 30px;
  top: 30px;
}

.card-number {
  font-size: 24px;
  font-weight: bold;
  margin-bottom: 20px;
  text-align: center;
}

.card-info {
  display: flex;
  justify-content: space-between;
  width: 100%;
  font-size: 14px;
  text-align: center;
}

// 金币动画样式
.falling-coin {
  position: absolute;
  top: -50px;
  color: $coin-color;
  animation: fall 3s linear forwards;
  z-index: 1;
}

// 登录选择界面样式
.select-login-container {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  height: 100vh;
  padding: 0 20px;
  box-sizing: border-box;
  background: $slider-bg;
}

.login-options-slider {
  width: 100%;
  max-width: 500px;
  margin-top: 30px;
}

.slider-track {
  display: flex;
  width: 100%;
  overflow: hidden;
  border-radius: 30px;
  background-color: white;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.slider-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  cursor: pointer;
  transition: all 0.3s ease;
  border-radius: 30px;
  opacity: 0.7;
  transform: scale(0.95);
}

.slider-item.active {
  opacity: 1;
  transform: scale(1);
  background-color: rgba(255, 255, 255, 0.7);
}

.icon-container {
  width: 60px;
  height: 60px;
  background-color: #f0f2f5;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 10px;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.1);
}

.login-button-container {
  margin-top: 30px;
}

.login-button {
  width: 100%;
  max-width: 300px;
  padding: 15px 30px;
  font-size: 16px;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
}

.login-button:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
}

// 动画关键帧
@keyframes fall {
  0% {
    transform: translateY(0) rotate(0deg);
    opacity: 0;
  }
  10% {
    opacity: 1;
  }
  80% {
    transform: translateY(100vh) rotate(360deg);
  }
  100% {
    transform: translateY(100vh) rotate(360deg);
    opacity: 0;
  }
}

@keyframes logoAppear {
  0% {
    transform: scale(0);
    opacity: 0;
  }
  70% {
    transform: scale(1.1);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes cardFloat {
  0% {
    transform: translateX(-50%) translateY(100px) rotate(-15deg);
    opacity: 0;
  }
  40% {
    transform: translateX(-50%) translateY(0) rotate(5deg);
  }
  70% {
    transform: translateX(-50%) translateY(-20px) rotate(-3deg);
  }
  100% {
    transform: translateX(-50%) translateY(0) rotate(0deg);
    opacity: 1;
  }
}
</style>